home *** CD-ROM | disk | FTP | other *** search
- Path: nwlink.com!usenet
- From: tjr19@mail.nwlink.com
- Newsgroups: comp.lang.c
- Subject: Re: Permutations
- Date: 4 Mar 1996 19:01:57 GMT
- Organization: Northwest Link
- Message-ID: <4hfen5$8uf@texas.nwlink.com>
- References: <Dn8yz9.GGy@spuddy.mew.co.uk> <4h1v27$cdc@texas.nwlink.com> <4h4rbn$7es@hpbblb.bbn.hp.com>
- NNTP-Posting-Host: port3.annex4.nwlink.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
-
- Matthias Dittrich <matti> wrote:
- >Teresa Reiko <tjr19@mail.nwlink.com> wrote:
- >>david@spuddy.mew.co.uk (David Turner) wrote:
- >>
- >>> Does anyone know of an algorithm that works out the different permutations
- >>>of ordering a number of objects? Not calculating how many there are, but
- >>>actaully working out (quickly?) what they permutations are!
- >>
- >>Untested code -- but this should work...
- >>Example: Permute("", "abcdef", 6)
- >>
- >>void Permute(char *p_prefix, char *p_list, int num)
- >>{
- >> int i;
- >> char s[10], p[10];
- >>
- >> if(num == 0)
- >> {
- >> printf("%s%s", prefix, p_list);
-
- >Here is a little bug: ^^^^^^
- >you mean p_prefix I think.
- >
- >(And the output is more readable if you append \n to the format string
- > :-)
-
- Yep, you're right. Oops.
-
- >> return;
- >> }
- >>
- >> for(i = 0; i < num; i++)
- >> < etc etc etc . . . >
-
- ----------------------------------------------------------------------
- Teresa Reiko Chief Programmer, Tenbyte Software tjr19@nwlink.com
- ----------------------------------------------------------------------
-
-
-